﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using TerminalTick.Models;

namespace TerminalTick.SignalR
{
    public class TerminalHub : Hub
    {
        private readonly TerminalTicker _terminalTicker;

        public TerminalHub(TerminalTicker terminalTicker)
        {
            _terminalTicker = terminalTicker;
        }

        public TerminalHub() : this(TerminalTicker.Instance) { }

        public IEnumerable<TerminalPoint> GetAllTerminals()
        {
            return TerminalStore.Instance.GetAll();            
        }

        public void CreateTerminal(int x, int y, string id, string hostname, int groupid)
        {
            TerminalPoint tp = new TerminalPoint();
            tp.X = x;
            tp.Y = y;
            tp.Id = id;
            if (TerminalStore.Instance.Add(tp))
            {
                Clients.Others.broadcast(x, y, new BroadcastMessage
                {
                    Id = tp.Id,
                    Title = String.Format("This is an new terminal({0},{1})", x, y)
                });
            }
        }
    }
}